<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <parent></parent>
    </div>
    <!-- 1.定义模板 -->
    <template id="parent">
        <div>
            <h2>父组件接收到子组件传过来的数据：{{pmsg}}</h2>
            <child @change="getVal"></child>
        </div>
    </template>

    <template id="child">
        <div>
            <button @click="fn">点击传值父组件</button>
            <h1>子组件准备传给父组件的数据：{{cmsg}}</h1>
        </div>
    </template>
</body>
</html>
<script src="js/vue.min.js"></script>
<script>
    var app=new Vue({
        el:"#app",
        components:{
            "parent":{
                template:"#parent",
                data:function(){
                    return {
                        pmsg:""
                    }
                },
                methods:{
                    getVal:function(val){
                        this.pmsg=val;
                    }
                },

                components:{
                    "child":{
                        template:"#child",
                        data:function(){
                            return {
                                cmsg:"1000"
                            }
                        },
                        methods:{
                            fn:function(){
                                //手动触发自定change事件
                                this.$emit("change",this.cmsg);
                            }
                        }
                    }
                }
            }
        }
    });
</script>